home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / barbu2 / ctlradio.cpp < prev    next >
C/C++ Source or Header  |  1995-05-08  |  2KB  |  107 lines

  1. // CTLRADIO implementation
  2. //////////////////////////////////////////////////////
  3. #include "CONTROLS.HPP"
  4. #include "KW.HPP"
  5.  
  6. CTLRADIO::CTLRADIO(const DESCRIPT& Desc,
  7.             SHOWDATA* Guru,
  8.             const CTLMAPPER* Map)
  9.     : CTL(Desc, Guru), _map(Map)
  10.  
  11. {
  12. STR Label;
  13. _desc.value(KW::LABEL, Label);
  14. _duwText = _map->duwText(Label);
  15.  
  16. MULTIPARAM Iter(&_desc, KW::R);
  17. _nR = Iter.no();
  18. int duwMaxText = 0;
  19. for(int i = 0; i < _nR; i++){
  20.     STR Rad;
  21.     Iter.value(i, Rad);
  22.     duwMaxText = max(duwMaxText, _map->duwText(Rad));
  23.     }
  24. _duwCombo = duwMaxText + _map->duSquareBox() + 8;
  25. _bInOneLine = (_duwText + _duwCombo) <
  26.                 ((2*_map->duwScreen()) / 3);
  27. if(_bInOneLine){
  28.     _duw = 1 + _duwText + _duwCombo;
  29.     _duh = _map->duSquareBox();
  30.     }
  31. else{
  32.     _duw = max(_duwText, _duwCombo);
  33.     _duh = 1 + _map->duhText() + _map->duSquareBox();
  34.     }
  35. }
  36.  
  37. CTLRADIO::~CTLRADIO()
  38. {
  39. }
  40.  
  41. int CTLRADIO::addToDlg(int nFirstFreeId,
  42.                         MEMBLOCK *pTemplate,
  43.                         int duX, int duY)
  44. {
  45. CTL::DLGITEM text(CTL::_Text);
  46. CTL::DLGITEM comb(CTL::_Combo);
  47.  
  48. text.dtilCX = _duwText;
  49. text.dtilCY = _map->duhText();
  50.  
  51. comb.dtilCX = _duwCombo;
  52. comb.dtilCY = _map->duSquareBox() + _nR * 8;
  53.  
  54. text.dtilX = duX;
  55. text.dtilY = duY;
  56. if(_bInOneLine){
  57.     text.dtilY += 1;
  58.     comb.dtilX = duX + _duwText + 1;
  59.     comb.dtilY = duY;
  60.     }
  61. else{
  62.     comb.dtilX = duX;
  63.     comb.dtilY = duY + _map->duhText() + 1;
  64.     }
  65. _idT = nFirstFreeId;
  66. _idCB = nFirstFreeId + 1;
  67.  
  68. text.dtilID = _idT;
  69. comb.dtilID = _idCB;
  70.  
  71. pTemplate->add((unsigned char*)&text, sizeof(text));
  72. pTemplate->add((unsigned char*)&comb, sizeof(comb));
  73. return 2;
  74. }
  75.  
  76. void CTLRADIO::dataToScreen()
  77. {
  78. STR Label;
  79. _desc.value(KW::LABEL, Label);
  80. SetDlgItemText(_hDlg, _idT, Label);
  81.  
  82. MULTIPARAM Iter(&_desc, KW::R);
  83. for(int i = 0; i < _nR; i++){
  84.     STR Rad;
  85.     Iter.value(i, Rad);
  86.     SendDlgItemMessage(_hDlg, _idCB, CB_INSERTSTRING,
  87.                         i, (LPARAM)(const char*)Rad);
  88.     }
  89.  
  90. STR Var;
  91. _desc.value(KW::VAR, Var);
  92. int val = _guru->get(Var);
  93. if(val < 0 || _nR <= val)
  94.     val = 0;
  95. SendDlgItemMessage(_hDlg, _idCB, CB_SETCURSEL, val, 0);
  96. }
  97.  
  98. void CTLRADIO::saveData()
  99. {
  100. int val = SendDlgItemMessage(_hDlg, _idCB,
  101.                 CB_GETCURSEL, 0, 0);
  102. STR Var;
  103. _desc.value(KW::VAR, Var);
  104. _guru->set(Var, val);
  105. }
  106.  
  107.